
import day from "./dayjs.min.js"
import {login as logins} from "@/api/app/api.js"

export function transformTime(time){
	let diffTime = Number(String(+new Date()).slice(0,10)) - Number(time);
	if (diffTime/60 < 60){
		return ''+profily(Math.ceil(diffTime/60),'分')+"分钟"
	}
	else if (diffTime/60/60 < 24){
		return ''+profily(Math.round(diffTime/60/60),'时')+"小时"
	}
	else if (diffTime/60/60/24 < 7){
		return ''+Math.round(diffTime/60/60/24)+"天"
	}
	else{
		return ''+Math.round(diffTime/60/60/24/7)+"周"
	}
};

function profily(val,types){
	if (val < 0){
		if(types == '分'){
			return val + 24 * 60
		}else if(types == '时'){
			return val + 24
		}else{
			return val
		}
	}else{
		return val
	}
}

export function transPlayCount(val){
	return Math.round(Number(val)/10000) + "万";
}


export function addDate(date, day){
	return day(date).add(day, 'day')
}

export function formatDay(time){
	console.log("time",time);
	return day(time).format('MM月DD日')
}

export function randId(len,isMix){
	let sun = '';
	for(let _index=0;_index<len;_index++){
		let num = Math.ceil(Math.random()*10);
		sun = sun + num;
	}
	return sun;
}

export function login(type){
	return new Promise((resolve,reject)=>{
		uni.login({
			success:async (res)=>{
				res['types'] = type
				let response = await logins(res)
				resolve(response.data)
			},
			fail:(err)=>{
				console.log(err)
				reject(err)
			}
		})
	})
}